/*
 * DCTableModel.java
 *
 * Created on 16 de Dezembro de 2004, 13:48
 */

package ceirinhashls.gui;

import ceirinhashls.DCHub;
import ceirinhashls.PublicHubList;
import ceirinhashls.gui.*;
import java.util.Comparator;

import javax.swing.table.*;
/**
 *
 * @author  botelhodaniel
 */
public class DCTableModel extends AbstractTableModel{
    /**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	public static int choosedColumn = -1;
	
	private PublicHubList hublist;
    private static String[] columnNames = new String [] {
                StringDef.HUB_NAME, StringDef.HUB_ADDRESS, StringDef.HUB_DESCRIPTION,
                StringDef.HUB_USERS,StringDef.HUB_SHARE,StringDef.HUB_COUNTRY,StringDef.HUB_STATUS,
                StringDef.HUB_MIN_SHARE,StringDef.HUB_MIN_SLOTS,StringDef.HUB_MAX_HUBS,
                StringDef.HUB_MAX_USERS,StringDef.HUB_RELIABILITY,StringDef.HUB_RATING,
                StringDef.HUB_PORT,
                //extensoes
                StringDef.HUB_LAST_UPDATE, StringDef.HUB_SOCKET_ADDRESS
            };
    public static Comparator getComparator(){
    	System.out.println("zxcxzcxzczcxzc : "+choosedColumn);
    	if(choosedColumn<0 || choosedColumn>13)
    		return null;
    	else
    		return getComparator(choosedColumn);
    }
    public static java.util.Comparator getComparator(int column) {
		switch (column) {
		case 0:
			return new java.util.Comparator() {
				public int compare(Object arg0, Object arg1) {
					return ((DCHub) arg0).getName().compareTo(
							((DCHub) arg1).getName());
				}
			};
		case 1:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getAddress().compareTo(
						((DCHub) arg1).getAddress());
			}
		};
		case 2:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getDescription().compareTo(
						((DCHub) arg1).getDescription());
			}
		};
		case 3:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return -new Integer(((DCHub) arg0).getUsers()).compareTo(
						new Integer(((DCHub) arg1).getUsers()));
			}
		};
		case 4:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getShared().compareTo(
						((DCHub) arg1).getShared());
			}
		};
		case 5:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getCountry().compareTo(
						((DCHub) arg1).getCountry());
			}
		};
		case 6:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getStatus().compareTo(
						((DCHub) arg1).getStatus());
			}
		};
		case 7:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getMinshare().compareTo(
						((DCHub) arg1).getMinshare());
			}
		};
		case 8:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getMinslots().compareTo(
						((DCHub) arg1).getMinslots());
			}
		};
		case 9:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getMaxhubs().compareTo(
						((DCHub) arg1).getMaxhubs());
			}
		};
		case 10:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getMaxusers().compareTo(
						((DCHub) arg1).getMaxusers());
			}
		};
		case 11:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getReliability().compareTo(
						((DCHub) arg1).getReliability());
			}
		};
		case 12:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return ((DCHub) arg0).getRating().compareTo(
						((DCHub) arg1).getRating());
			}
		};
		case 13:
			return new java.util.Comparator() {
			public int compare(Object arg0, Object arg1) {
				return new Integer(((DCHub) arg0).getPort()).compareTo(
						new Integer(((DCHub) arg1).getPort()));
			}
		};
		}
		return null;
	}
    /** Creates a new instance of DCTableModel */
    public DCTableModel(PublicHubList hublist) {
        this.hublist = hublist;
    }
    
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
    public boolean isCellEditable(int row, int col) {
        return false;
    }
    
    public int getColumnCount() {
        return columnNames.length;
    }
    public String getColumnName(int col) {
        return columnNames[col];
    }
    public int getRowCount() {
        return hublist.getSize();
    }
    
    public Object getValueAt(int param, int param1) {
        return hublist.getValueAt(param,param1);
    }
    
}
